﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Project.Engine.Utilities;

namespace Project.Module.DAO.BL
{
    public class ProcessUrl
    {
        public static int GetIdByUrl(string url) {
            int id = 0;
            string[] arr = url.Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries);
            if (arr.Length > 0) {
                id = ConvertUtil.ToInt32(arr[1].Replace(("id="),String.Empty));
            }

            return id;
        }

        public static string GetCateNameByUrl(string url)
        {
            string cateName = String.Empty;
            string[] arr = url.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            if (arr.Length >= 0)
            {
                cateName = ConvertUtil.ToString(arr[1]);
            }

            return cateName;
        }

        /// <summary>
        /// return page index from url
        /// Ex:
        ///     http://project.com/nguyen-lieu-lam-banh?2
        ///     return 2;
        ///     page index = 2
        /// </summary>
        /// <param name="url"></param>
        /// <returns>page index</returns>
        public static int GetPageIdByUrl(string url) {
            int pageId = 0;
            string[] arr = url.Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries);
            if (arr.Length >= 2)
            {
                pageId = ConvertUtil.ToInt32(arr[1]);
            }

            return pageId;
        }
    }
}
